<extend name="Public:Base" />
<block name="content">
	<div class="main-title">
		<h2><eq name="ACTION_NAME" value='add'>新增<else />编辑</eq>角色 [ <A HREF="__URL__">返回列表</A> ]</h2>
	</div>
	<FORM METHOD="POST" id="form1" class="form-horizontal" action="__URL__/<eq name="ACTION_NAME" value="add">insert<else />update</eq>" enctype="multipart/form-data">
		<div class="form-item cf">
			<label class="item-label">角色名称：<span class="check-tips">（输入角色名称）</span></label>
			<div class="controls">
				<input type="text" class="text input-large" name="title" value="{$vo.title}" datatype="*" nullmsg="角色名称不能为空!" ajaxurl="__URL__/checkTitle">
			</div>
		</div>
		<div class="form-item cf">
			<label class="item-label">角色权限：<span class="check-tips">（输入行为标识 英文字母）</span></label>
			<div class="controls">
				<volist name="AuthList" id="vo1">
                <fieldset class="mws-form-inline Group" id="Group_{$vo1.id}">
                    <legend class="wizard-label">
                        <i class="icol-accept"></i>
                        <input type="checkbox" class="GroupCheckbox">&nbsp;&nbsp;{$vo1.title}
                    </legend>
                    <div id="Child_{$vo1.id}" style="margin-left:50px;">
                    <volist name="vo1.rules" id="vo2">
                        <label class="mws-form-label"><input name="rules[]" type="checkbox" id="ChildNode{$vo2.id}" value="{$vo2.id}" class="ChildNode">&nbsp;&nbsp;{$vo2.title}</label>
                    </volist>
                    </div>
                </fieldset>
                </volist>
			</div>
		</div>
		<div class="form-item">
			<INPUT TYPE="hidden" name="id" value="{$vo.id}">
			<INPUT TYPE="hidden" name="jumpurl" value="{$Think.server.HTTP_REFERER}">
			<button type="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定</button>
			<button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
		</div>
	</FORM>
</block>
<block name="__body">
	<script type="text/javascript">
        function init(){
            var rules='{$vo.rules}';
            rules=rules.split(',');
            for (var i = 0; i < rules.length; i++) {
                $('#ChildNode'+rules[i]).attr('checked',true);
            }
            $('.Group').each(function(){
                if($(this).find('.ChildNode:checked').length==$(this).find(':checkbox.ChildNode').length){
                   $(this).attr('checked',true);
                }
            });
            //checkChecked();
        }
        function checkChecked(id){

        }
        $(function(){
            $(':checkbox').attr('checked',false);
            init();
            $('.GroupCheckbox').change(function(){
                $(this).parent().parent().find('.ChildNode').attr('checked',!!$(this).attr('checked'));
            });
            $('.ChildNode').change(function(){
                var check=!$(this).attr('checked');
                var parent=$(this).parent().parent();
                var parentCheck=parent.parent().find('.GroupCheckbox');
                if(check){
                   parentCheck.attr('checked',false);
                }
                if(parent.find(':checked').length==parent.find(':checkbox').length){
                   parentCheck.attr('checked',true);
                }
            });
            $('#form1').Validform({
                tiptype:function(msg,o,cssctl){
                    if(!o.obj.is("form")){
                        var infoObj=o.obj.parent().find(".mws-error");
                        if (!infoObj || infoObj.length==0){
                            o.obj.after('<div class="mws-error"></div>');
                        }
                        infoObj=o.obj.parent().find(".mws-error");
                        if(o.type==2){
                            o.obj.removeClass('error');
                            infoObj.hide();
                        }else{
                            o.obj.addClass('error');
                            infoObj.html(msg).show();
                        }
                    }
                }
            });
        })
	</script>
</block>